package com.caseprocessing.model;

/**
 * 文书类型枚举
 * 基于GB/T 9705-2008标准定义的常见文书类型
 */
public enum DocumentType {
    
    COVER("封面", "案卷封面页"),
    DIRECTORY("目录", "卷内文件目录"),
    CASE_DECISION("处罚决定书", "行政处罚决定书"),
    EVIDENCE_LIST("证据清单", "案件证据清单"),
    INVESTIGATION_RECORD("调查笔录", "调查询问笔录"),
    HEARING_RECORD("听证笔录", "听证会议笔录"),
    NOTIFICATION("告知书", "行政处罚事先告知书"),
    DEFENSE_STATEMENT("申辩书", "当事人申辩材料"),
    REVIEW_OPINION("复查意见书", "复查复议意见"),
    EXECUTION_RECORD("执行记录", "处罚执行情况记录"),
    BACKUP_TABLE("备考表", "卷内备考表"),
    OTHER("其他文书", "未分类文书");
    
    private final String code;
    private final String description;
    
    DocumentType(String code, String description) {
        this.code = code;
        this.description = description;
    }
    
    public String getCode() {
        return code;
    }
    
    public String getDescription() {
        return description;
    }
    
    /**
     * 根据文书标题判断文书类型
     */
    public static DocumentType fromTitle(String title) {
        if (title == null || title.trim().isEmpty()) {
            return OTHER;
        }
        
        String normalizedTitle = title.trim().toLowerCase();
        
        if (normalizedTitle.contains("处罚决定书") || normalizedTitle.contains("行政处罚")) {
            return CASE_DECISION;
        } else if (normalizedTitle.contains("证据清单") || normalizedTitle.contains("证据目录")) {
            return EVIDENCE_LIST;
        } else if (normalizedTitle.contains("调查笔录") || normalizedTitle.contains("询问笔录")) {
            return INVESTIGATION_RECORD;
        } else if (normalizedTitle.contains("听证笔录") || normalizedTitle.contains("听证记录")) {
            return HEARING_RECORD;
        } else if (normalizedTitle.contains("告知书") || normalizedTitle.contains("事先告知")) {
            return NOTIFICATION;
        } else if (normalizedTitle.contains("申辩书") || normalizedTitle.contains("申辩材料")) {
            return DEFENSE_STATEMENT;
        } else if (normalizedTitle.contains("复查意见") || normalizedTitle.contains("复议意见")) {
            return REVIEW_OPINION;
        } else if (normalizedTitle.contains("执行记录") || normalizedTitle.contains("执行情况")) {
            return EXECUTION_RECORD;
        } else if (normalizedTitle.contains("封面")) {
            return COVER;
        } else if (normalizedTitle.contains("目录") || normalizedTitle.contains("卷内文件")) {
            return DIRECTORY;
        } else if (normalizedTitle.contains("备考表")) {
            return BACKUP_TABLE;
        }
        
        return OTHER;
    }
    
    /**
     * 获取该类型文书的关键词列表
     */
    public String[] getKeywords() {
        switch (this) {
            case CASE_DECISION:
                return new String[]{"处罚决定书", "行政处罚", "决定", "处罚"};
            case EVIDENCE_LIST:
                return new String[]{"证据清单", "证据目录", "证据材料", "证据"};
            case INVESTIGATION_RECORD:
                return new String[]{"调查笔录", "询问笔录", "调查记录", "笔录"};
            case HEARING_RECORD:
                return new String[]{"听证笔录", "听证记录", "听证会", "听证"};
            case NOTIFICATION:
                return new String[]{"告知书", "事先告知", "通知书", "告知"};
            case DEFENSE_STATEMENT:
                return new String[]{"申辩书", "申辩材料", "陈述申辩", "申辩"};
            case REVIEW_OPINION:
                return new String[]{"复查意见", "复议意见", "复查", "复议"};
            case EXECUTION_RECORD:
                return new String[]{"执行记录", "执行情况", "执行", "履行"};
            default:
                return new String[]{};
        }
    }
}